 <?php
   include('_config.inc.php');

 function getLastInsertId()
{
   $result = 0;
   if($query_result = mysql_query("SELECT LAST_INSERT_ID()"))
   {
      $temp = mysql_fetch_row($query_result);
      $result = $temp[0];
   }

   return $result;
}
         mysql_connect('localhost','root','');
         mysql_select_db('nomade');

        extract($_POST);
        if (isset($_POST["objectif"])&&isset($_POST["designation"])&&isset($_POST["datedebut"])&&isset($_POST["nomade"])) {
        $req="insert into tache(objectif,designation,dateDebut) value('$objectif','$designation','$datedebut')";
        mysql_query($req);
        echo "tache insere";
        $ch=explode(" ",$nomade);
        $nomnomade=$ch[0];
        $idtache=getLastInsertId();
        $req="select idNomade from nomade where nom like '$nomnomade'";
        $result=mysql_query($req);
        while($row = mysql_fetch_row($result)) {
          $idnomade=$row[0];
          }
        $req2="insert into intervention(idNomade,idTache) value($idnomade,$idtache)";
        mysql_query($req2);
        echo "interv insere";
        $idinterv=getLastInsertId();
        //$explore = explode('-',$_POST['nomade']);
        $req3="insert into nomade_intervention value($idnomade,$idinterv,'$datedebut')";
        mysql_query($req3);
        echo "interv_nomade insere";
          }



        $req="select * from nomade";
        $result=mysql_query($req);
        while($row = mysql_fetch_row($result)) {
        $var=$row[2].'  '.$row[3];
        $tab[$row[0]] = $var;
         }

        $datnow=date('d/m/Y');
        $tpl->assign('d',$datnow);
        $tpl->assign('tab',$tab);
        $tpl->display("dem_interv.html");
        ?>